package com.endbd.warehouse.controller;

import com.endbd.feignapi.api.MarketingApi;
import com.endbd.feignapi.api.PurchaseApi;
import com.endbd.feignapi.model.marketing.Orderdetails;
import com.endbd.feignapi.model.purchase.CPurchase;
import com.endbd.feignapi.model.warehouse.RkWarehouse;
import com.endbd.feignapi.util.PageModel;
import com.endbd.feignapi.util.ResultMessage;
import com.endbd.warehouse.model.IDCondition;
import com.endbd.warehouse.model.RKCondition;
import com.endbd.warehouse.service.IManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/warehouse")
public class RKWarehouseAction {
    @Autowired
    private IManageService manageService;
    public IManageService getManageService() {
        return manageService;
    }
    public void setManageService(IManageService manageService) {
        this.manageService = manageService;
    }

    @Autowired
    private PurchaseApi purchaseApi;

    @RequestMapping("/rkPageBean")
    @ResponseBody
    public PageModel<RkWarehouse> queryRK(RKCondition rkc, PageModel<RkWarehouse> pageModel){
        PageModel<RkWarehouse> pageBean = manageService.queryRK(rkc,pageModel);
        return pageBean;
    }

    @RequestMapping("/rkUpdate")
    @ResponseBody
    public int queryRK(String id,String state){
        int count = manageService.updateRKState(id,state);
        return count;
    }

    @RequestMapping("/test2")
    @ResponseBody
    public ResultMessage test(String orderId) {
        System.out.println(orderId);
        ResultMessage resultMessage = new ResultMessage();
        ResultMessage orderDetails = purchaseApi.queryDetailById(orderId);
        return orderDetails;
    }

    @RequestMapping("/changeRRk")
    @ResponseBody
    public int changeRk(IDCondition idc){
        int count = manageService.changRk2(idc);
        return count;
    }

    @RequestMapping("/addRK")
    @ResponseBody
    public int addRK(RkWarehouse rkw){
        int count = manageService.addRK(rkw);
        return count;
    }

    @RequestMapping("/rkDetail")
    @ResponseBody
    public ResultMessage rkDetail(){
        ResultMessage resultMessage = purchaseApi.queryPageByCondition(3, 1);
        return resultMessage;
    }

//    修改采购单
    @RequestMapping("/caigao")
    @ResponseBody
    public ResultMessage caigao(String rkIndent,String warehouseId){
        ResultMessage rm = purchaseApi.updateWarehouseIdAndRkStatus(rkIndent, warehouseId);
        return rm;
    }
}
